home *** CD-ROM | disk | FTP | other *** search
/ LG Super CD / LG Super CD.iso / bitpim / bitpim-0.62-setup.exe / {app} / bitpim.exe / common.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-06  |  6.4 KB  |  148 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.3)
  3.  
  4. import string
  5. import cStringIO
  6.  
  7. class CommsException(Exception):
  8.     
  9.     def __init__(self, device, message):
  10.         Exception.__init__(self, '%s: %s' % (device, message))
  11.         self.device = device
  12.         self.message = message
  13.  
  14.  
  15.  
  16. class CommsNeedConfiguring(CommsException):
  17.     
  18.     def __init__(self, device, message):
  19.         CommsException.__init__(self, device, message)
  20.         self.device = device
  21.         self.message = message
  22.  
  23.  
  24.  
  25. class CommsDeviceNeedsAttention(CommsException):
  26.     
  27.     def __init__(self, device, message):
  28.         CommsException.__init__(self, device, message)
  29.         self.device = device
  30.         self.message = message
  31.  
  32.  
  33.  
  34. class CommsTimeout(CommsException):
  35.     
  36.     def __init__(self, device, message):
  37.         CommsException.__init__(self, device, message)
  38.         self.device = device
  39.         self.message = message
  40.  
  41.  
  42.  
  43. class CommsOpenFailure(CommsException):
  44.     
  45.     def __init__(self, device, message):
  46.         CommsException.__init__(self, device, message)
  47.         self.device = device
  48.         self.message = message
  49.  
  50.  
  51.  
  52. class AutoPortsFailure(CommsException):
  53.     
  54.     def __init__(self, portstried):
  55.         self.device = 'auto'
  56.         self.message = 'Failed to auto-detect the port to use.  '
  57.         CommsException.__init__(self, self.device, self.message)
  58.  
  59.  
  60.  
  61. def datatohexstring(data):
  62.     res = cStringIO.StringIO()
  63.     lchar = ''
  64.     lhex = '00000000 '
  65.     for count in range(0, len(data)):
  66.         b = ord(data[count])
  67.         lhex = lhex + '%02x ' % (b,)
  68.         if b >= 32 and string.printable.find(chr(b)) >= 0:
  69.             lchar = lchar + chr(b)
  70.         else:
  71.             lchar = lchar + '.'
  72.         if (count + 1) % 16 == 0:
  73.             res.write(lhex + '    ' + lchar + '\n')
  74.             lhex = '%08x ' % (count + 1,)
  75.             lchar = ''
  76.             continue
  77.     
  78.     if len(data):
  79.         while (count + 1) % 16 != 0:
  80.             count = count + 1
  81.             lhex = lhex + '   '
  82.         res.write(lhex + '    ' + lchar + '\n')
  83.     
  84.     return res.getvalue()
  85.  
  86.  
  87. def prettyprintdict(dictionary, indent = 0):
  88.     res = ''
  89.     istr = '  '
  90.     res += '%s{\n' % (istr * indent,)
  91.     indent += 1
  92.     keys = dictionary.keys()
  93.     keys.sort()
  94.     for k in keys:
  95.         v = dictionary[k]
  96.         if isinstance(v, dict):
  97.             res += '%s%s:\n%s,\n' % (istr * indent, `k`, prettyprintdict(v, indent + 1))
  98.             continue
  99.         res += '%s%s: %s,\n' % (istr * indent, `k`, `v`)
  100.     
  101.     indent -= 1
  102.     res += '%s}\n' % (istr * indent,)
  103.     return res
  104.  
  105.  
  106. class exceptionwrap:
  107.     
  108.     def __init__(self, callable):
  109.         self.callable = callable
  110.  
  111.     
  112.     def __call__(self, *args, **kwargs):
  113.         
  114.         try:
  115.             print 'in exception wrapped call'
  116.             res = self.callable(*args, **kwargs)
  117.             print `self.callable`, 'returned', datatohexstring(res)
  118.             return res
  119.         except:
  120.             import traceback
  121.             traceback.print_stack()
  122.             traceback.print_exc()
  123.             raise 
  124.  
  125.  
  126.  
  127.  
  128. def readversionedindexfile(filename, dict, versionhandlerfunc, currentversion):
  129.     execfile(filename, dict, dict)
  130.     if not dict.has_key('FILEVERSION'):
  131.         version = 0
  132.     else:
  133.         version = dict['FILEVERSION']
  134.         del dict['FILEVERSION']
  135.     if version < currentversion:
  136.         versionhandlerfunc(dict, version)
  137.     
  138.  
  139.  
  140. def writeversionindexfile(filename, dict, currentversion):
  141.     f = open(filename, 'w')
  142.     for key in dict:
  143.         f.write("result['%s']=%s\n" % (key, prettyprintdict(dict[key])))
  144.     
  145.     f.write('FILEVERSION=%d\n' % (currentversion,))
  146.     f.close()
  147.  
  148.